import { createSlice } from '@reduxjs/toolkit';
import axios from 'axios';

const channelStore = createSlice({
    name: 'channel',
    initialState: {
        channels: []
    },
    reducers: {
        setChannels: (state, action) => {
            state.channels = action.payload
        }
    }
})

const { setChannels } = channelStore.actions


const fetchCh = () => {

    return async (dispatch) => {
        const res = await axios.get('http://localhost:8080/s4/channel/queryChannels')
        dispatch(setChannels(res.data))
    }

}

export { fetchCh}

const channelReducer = channelStore.reducer

export default channelReducer